<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人资料 - 学生知识管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: #f5f5f5;
            line-height: 1.6;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .nav {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 2rem;
        }
        
        .logo {
            font-size: 1.5rem;
            font-weight: bold;
        }
        
        .nav-links {
            display: flex;
            list-style: none;
            gap: 2rem;
        }
        
        .nav-links a {
            color: white;
            text-decoration: none;
            transition: opacity 0.3s;
        }
        
        .nav-links a:hover {
            opacity: 0.8;
        }
        
        .container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 2rem;
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 2rem;
        }
        
        .sidebar {
            background: white;
            border-radius: 10px;
            padding: 2rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            height: fit-content;
        }
        
        .profile-avatar {
            text-align: center;
            margin-bottom: 2rem;
        }
        
        .avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            background: #667eea;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 3rem;
            color: white;
            margin: 0 auto 1rem;
        }
        
        .sidebar-menu {
            list-style: none;
        }
        
        .sidebar-menu li {
            margin-bottom: 0.5rem;
        }
        
        .sidebar-menu a {
            display: block;
            padding: 0.75rem 1rem;
            color: #333;
            text-decoration: none;
            border-radius: 5px;
            transition: background 0.3s;
        }
        
        .sidebar-menu a:hover,
        .sidebar-menu a.active {
            background: #667eea;
            color: white;
        }
        
        .main-content {
            background: white;
            border-radius: 10px;
            padding: 2rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .content-header {
            border-bottom: 1px solid #eee;
            padding-bottom: 1rem;
            margin-bottom: 2rem;
        }
        
        .content-header h1 {
            color: #333;
            font-size: 1.8rem;
        }
        
        .form-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1.5rem;
            margin-bottom: 2rem;
        }
        
        .form-group {
            margin-bottom: 1.5rem;
        }
        
        .form-group.full-width {
            grid-column: 1 / -1;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: #333;
            font-weight: 500;
        }
        
        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        
        .form-group input:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
        }
        
        .form-group textarea {
            resize: vertical;
            min-height: 100px;
        }
        
        .btn {
            padding: 0.75rem 1.5rem;
            border: none;
            border-radius: 5px;
            font-size: 1rem;
            cursor: pointer;
            transition: background 0.3s;
        }
        
        .btn-primary {
            background: #667eea;
            color: white;
        }
        
        .btn-primary:hover {
            background: #5a6fd8;
        }
        
        .btn-secondary {
            background: #6c757d;
            color: white;
            margin-left: 1rem;
        }
        
        .btn-secondary:hover {
            background: #5a6268;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }
        
        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1.5rem;
            border-radius: 10px;
            text-align: center;
        }
        
        .stat-number {
            font-size: 2rem;
            font-weight: bold;
            margin-bottom: 0.5rem;
        }
        
        .stat-label {
            opacity: 0.9;
        }
        
        .alert {
            padding: 1rem;
            border-radius: 5px;
            margin-bottom: 1rem;
        }
        
        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .alert-error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        @media (max-width: 768px) {
            .container {
                grid-template-columns: 1fr;
                gap: 1rem;
            }
            
            .form-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <nav class="nav">
            <div class="logo">🎓 学生知识管理系统</div>
            <ul class="nav-links">
                <li><a href="/">首页</a></li>
                <li><a href="/articles">文章</a></li>
                <li><a href="/categories">分类</a></li>
                <li><a href="/profile">个人中心</a></li>
                <li><a href="/logout">退出</a></li>
            </ul>
        </nav>
    </header>
    
    <div class="container">
        <aside class="sidebar">
            <div class="profile-avatar">
                <div class="avatar" th:if="${user.avatar == null}" th:text="${user.nickname != null ? user.nickname.substring(0,1) : user.username.substring(0,1)}">U</div>
                <img th:if="${user.avatar != null}" th:src="${user.avatar}" alt="用户头像" class="avatar" style="width: 60px; height: 60px; border-radius: 50%; object-fit: cover;">
                <h3 th:text="${user.nickname != null ? user.nickname : user.username}">用户名</h3>
                <p th:text="${user.email}">email@example.com</p>
            </div>
            
            <ul class="sidebar-menu">
                <li><a href="/profile" class="active">📝 个人资料</a></li>
                <li><a href="/profile/avatar">🖼️ 头像管理</a></li>
                <li><a href="/profile/points">⭐ 积分管理</a></li>
                <li><a href="/profile/articles">📚 我的文章</a></li>
                <li><a href="/profile/favorites">❤️ 我的收藏</a></li>
                <li><a href="/profile/follows">👥 我的关注</a></li>
                <li><a href="/profile/messages">💬 消息中心</a></li>
            </ul>
        </aside>
        
        <main class="main-content">
            <div class="content-header">
                <h1>个人资料</h1>
            </div>
            
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-number" th:text="${user.points ?: 0}">0</div>
                    <div class="stat-label">积分</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" th:text="${articleCount ?: 0}">0</div>
                    <div class="stat-label">文章数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" th:text="${favoriteCount ?: 0}">0</div>
                    <div class="stat-label">收藏数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" th:text="${followCount ?: 0}">0</div>
                    <div class="stat-label">关注数</div>
                </div>
            </div>
            
            <div th:if="${success}" class="alert alert-success" th:text="${success}"></div>
            <div th:if="${error}" class="alert alert-error" th:text="${error}"></div>
            
            <form action="/profile/update" method="post">
                <div class="form-grid">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" id="username" name="username" th:value="${user.username}" readonly>
                    </div>
                    
                    <div class="form-group">
                        <label for="email">邮箱</label>
                        <input type="email" id="email" name="email" th:value="${user.email}" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="nickname">昵称</label>
                        <input type="text" id="nickname" name="nickname" th:value="${user.nickname}" placeholder="请输入昵称">
                    </div>
                    
                    <div class="form-group">
                        <label for="realName">真实姓名</label>
                        <input type="text" id="realName" name="realName" th:value="${user.realName}" placeholder="请输入真实姓名">
                    </div>
                    
                    <div class="form-group">
                        <label for="phone">手机号</label>
                        <input type="tel" id="phone" name="phone" th:value="${user.phone}" placeholder="请输入手机号">
                    </div>
                    
                    <div class="form-group full-width">
                        <label for="bio">个人简介</label>
                        <textarea id="bio" name="bio" th:text="${user.bio}" placeholder="介绍一下自己..."></textarea>
                    </div>
                </div>
                
                <button type="submit" class="btn btn-primary">保存修改</button>
                <a href="/profile/password" class="btn btn-secondary">修改密码</a>
            </form>
        </main>
    </div>
</body>
</html>